import numpy as np
import matplotlib.pyplot as plt

data=([-1,0],[0,0],[0,1],[1,0],[1,1])
data=np.asarray(data)

r1=0.2
r2=0.5
r3=0.71

def get_axs(ax, data, r):
    return(ax)


fig, axs = plt.subplots(3, 2, sharex=False, sharey=False, layout='constrained')

axs[0,0].scatter(data[:,0], data[:,1], color='black')
axs[0,0].set_xlim(-2,2)
axs[0,0].set_ylim(-1,2)
axs[0,0].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[0,0].set_yticks([0,1], labels=['0','1'], size=6)
axs[0,0].set_xlabel('X-Axis', fontsize=6)
axs[0,0].set_ylabel('Y-Axis', fontsize=6)
axs[0,0].set_title(r'A) Geometric $\breve{C}$ech Complex of Radius ' + '%0.2f' % r1, fontsize=6)
axs[0,0].annotate('a', xy=[-0.1,1.35], fontsize=12)
axs[0,0].annotate('b', xy=[0.92,1.35], fontsize=12)
axs[0,0].annotate('c', xy=[-0.1,-0.7], fontsize=12)
axs[0,0].annotate('d', xy=[0.92,-0.7], fontsize=12)
axs[0,0].annotate('e', xy=[-1.08,-0.7], fontsize=12)
for i in range(0, data.shape[0]):
  c = plt.Circle(data[i,:], radius=r1, color='black')
  axs[0,0].add_patch(c)

axs[1,0].scatter(data[:,0], data[:,1], color='black')
axs[1,0].set_xlim(-2,2)
axs[1,0].set_ylim(-1,2)
axs[1,0].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[1,0].set_yticks([0,1], labels=['0','1'], size=6)
axs[1,0].set_xlabel('X-Axis', fontsize=6)
axs[1,0].set_ylabel('Y-Axis', fontsize=6)
axs[1,0].set_title(r'C) Geometric $\breve{C}$ech Complex of Radius ' + '%0.2f' % r2, fontsize=6)
for i in range(0, data.shape[0]):
  c = plt.Circle(data[i,:], radius=r2, color='black')
  axs[1,0].add_patch(c)

axs[2,0].scatter(data[:,0], data[:,1], color='black')
axs[2,0].set_xlim(-2,2)
axs[2,0].set_ylim(-1,2)
axs[2,0].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[2,0].set_yticks([0,1], labels=['0','1'], size=6)
axs[2,0].set_xlabel('X-Axis', fontsize=6)
axs[2,0].set_ylabel('Y-Axis', fontsize=6)
axs[2,0].set_title(r'E) Geometric $\breve{C}$ech Complex of Radius ' + '%0.2f' % r3, fontsize=6)
for i in range(0, data.shape[0]):
  c = plt.Circle(data[i,:], radius=r3, color='black')
  axs[2,0].add_patch(c)


'''
axs[1,0].text(0.5,0.5, 'Radius ' + '%0.2f' % r1 + 'D) Vietoris Rips Complex:\n' + r'$VR_{0.20}$ = {{a},{b},{c},{d},{}}', fontsize=14, va='center', ha='center')
axs[1,1].text(0.5,0.5, 'Radius ' + '%0.2f' % r2 + 'E) Vietoris Rips Complex:\n' + r'$VR_{0.50}$ = $VR_{0.20} \cup$ {{a,b},{b,c},{c,d},{d,a}', fontsize=14, va='center', ha='center')
axs[1,2].text(0.5,0.5, 'Radius ' + '%0.2f' % r3 + 'F) Vietoris Rips Complex:\n' + r'$VR_{0.71}$ = $VR_{0.50} \cup$ {{a,b,c},{a,b,d},{a,c,d,},{b,c,d},{a,b,c,d}}', fontsize=14, va='center', ha='center')
'''

axs[0,1].scatter(data[:,0], data[:,1], color='gray')
axs[0,1].set_xlim(-2,2)
axs[0,1].set_ylim(-1,2)
axs[0,1].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[0,1].set_yticks([0,1], labels=['0','1'], size=6)
axs[0,1].set_xlabel('X-axis', fontsize=6)
axs[0,1].set_ylabel('Y-axis', fontsize=6)
axs[0,1].set_title('B) Geometric Realization of Radius ' + '%0.2f' % r1 + ' Vietoris Rips Complex\n' + r'$VR_{0.20}$ = {{a},{b},{c},{d},{})', fontsize=6)

axs[1,1].scatter(data[:,0], data[:,1], color='gray')
axs[1,1].set_xlim(-1.5,1.5)
axs[1,1].set_ylim(-0.5,1.5)
axs[1,1].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[1,1].set_yticks([0,1], labels=['0','1'], size=6)
axs[1,1].set_xlabel('X-axis', fontsize=6)
axs[1,1].set_ylabel('Y-axis', fontsize=6)
axs[1,1].set_title('D) Geometric Realization of Radius ' + '%0.2f' % r2 + ' Vietoris Rips Complex\n' + r'$VR_{0.50} = VR_{0.20}\ \bigcup\ $ {{a,b},{b,c},{c,d},{d,a})', fontsize=6)
axs[1,1].plot([0,1],[1,1], color='gray', linewidth=4)
axs[1,1].plot([1,1],[1,0], color='gray', linewidth=4)
axs[1,1].plot([1,0],[0,0], color='gray', linewidth=4)
axs[1,1].plot([0,0],[0,1], color='gray', linewidth=4)
axs[1,1].plot([-1,0],[0,0], color='gray', linewidth=4)
#plt.grid(False)

axs[2,1].scatter(data[:,0], data[:,1], color='gray')
axs[2,1].set_xlim(-1.5,1.5)
axs[2,1].set_ylim(-0.5,1.5)
axs[2,1].set_xticks([-1,0,1], labels=['-1','0','1'], size=6)
axs[2,1].set_yticks([0,1], labels=['0','1'], size=6)
axs[2,1].set_xlabel('X-axis', fontsize=6)
axs[2,1].set_ylabel('Y-axis', fontsize=6)
axs[2,1].set_title('F) Geometric Realization of Radius ' + '%0.2f' % r3 + ' Vietoris Rips Complex\n' + r'$VR_{0.71} = VR_{0.50}\ \bigcup\ $ {{a,b,c},{a,b,d},{a,c,d},{b,c,d},{a,b,c,d})', fontsize=6)
x=np.asarray([0,1])
y1=np.asarray([0,0])
y2=np.asarray([1,1])
plt.fill_between(x,y1,y2,facecolor='gray')
plt.plot([0,1],[1,1],color='gray',linewidth=4)
plt.plot([0,1],[0,0],color='gray',linewidth=4)
plt.plot([0,0],[1,0],color='gray',linewidth=4)
plt.plot([1,1],[1,0],color='gray',linewidth=4)
plt.plot([-1,0],[0,0],color='gray',linewidth=4)
#plt.grid(False)

plt.savefig('/home/hunter/ekg/afib2/figures/vietoris_rips_example.eps', format='eps', dpi=1200)
#plt.savefig('/home/hunter/ekg/afib2/figures/vietoris_rips_example.png', format='png', dpi=1200)
#plt.show()


'''
plt.subplot(3,3,1)
plt.scatter(data[:,0],data[:,1],color='black')
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
c1=plt.Circle((0,0),radius=r1)
c2=plt.Circle((0,1),radius=r1)
c3=plt.Circle((1,0),radius=r1)
c4=plt.Circle((1,1),radius=r1)
c5=plt.Circle((10,10),radius=r1)
c6=plt.Circle((10,15),radius=r1)
c7=plt.Circle((15,10),radius=r1)
c8=plt.Circle((15,15),radius=r1)
plt.gca().add_artist(c1)
plt.gca().add_artist(c2)
plt.gca().add_artist(c3)
plt.gca().add_artist(c4)
plt.gca().add_artist(c5)
plt.gca().add_artist(c6)
plt.gca().add_artist(c7)
plt.gca().add_artist(c8)
plt.grid(False)
plt.title('A) Geometric Cech Complex of Radius ' + '%0.2f' % r1)
 
plt.subplot(3,3,2)
plt.scatter(data[:,0],data[:,1],color='red')
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
c1=plt.Circle((0,0),radius=r2)
c2=plt.Circle((0,1),radius=r2)
c3=plt.Circle((1,0),radius=r2)
c4=plt.Circle((1,1),radius=r2)
c5=plt.Circle((10,10),radius=r2)
c6=plt.Circle((10,15),radius=r2)
c7=plt.Circle((15,10),radius=r2)
c8=plt.Circle((15,15),radius=r2)
plt.gca().add_artist(c1)
plt.gca().add_artist(c2)
plt.gca().add_artist(c3)
plt.gca().add_artist(c4)
plt.gca().add_artist(c5)
plt.gca().add_artist(c6)
plt.gca().add_artist(c7)
plt.gca().add_artist(c8)
plt.grid(False)
plt.title('B) Geometric Cech Complex of Radius ' + '%0.2f' % r2)

plt.subplot(3,3,3)
plt.scatter(data[:,0],data[:,1],color='red')
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
c1=plt.Circle((0,0),radius=r3)
c2=plt.Circle((0,1),radius=r3)
c3=plt.Circle((1,0),radius=r3)
c4=plt.Circle((1,1),radius=r3)
c5=plt.Circle((10,10),radius=r3)
c6=plt.Circle((10,15),radius=r3)
c7=plt.Circle((15,10),radius=r3)
c8=plt.Circle((15,15),radius=r3)
plt.gca().add_artist(c1)
plt.gca().add_artist(c2)
plt.gca().add_artist(c3)
plt.gca().add_artist(c4)
plt.gca().add_artist(c5)
plt.gca().add_artist(c6)
plt.gca().add_artist(c7)
plt.gca().add_artist(c8)
plt.grid(False)
plt.title('C) Geometric Cech Complex of Radius ' + '%0.2f' % r3)



plt.subplot(3,3,4)
plt.set_axis_off()
plt.annotate('hello world')

plt.subplot(3,3,5)
plt.set_axis_off()
plt.annotate('hello world')

plt.subplot(3,3,6)
plt.annotate('hello world')
plt.set_axis_off()


plt.subplot(3,3,7)
plt.scatter(data[:,0],data[:,1],color='red',s=50)
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.grid(False)
plt.title('D) Geometric Realization of\n Radius ' +  '%0.2f' % r1 +' Vietoris-Rips Complex')

plt.subplot(3,3,8)
plt.scatter(data[:,0],data[:,1],color='black',s=50)
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.plot([0,1],[1,1],color='red',linewidth=4)
plt.plot([0,1],[0,0],color='red',linewidth=4)
plt.plot([0,0],[1,0],color='red',linewidth=4)
plt.plot([1,1],[1,0],color='red',linewidth=4)
plt.grid(False)
plt.title('E) Geometric Realization of\n Radius ' +  '%0.2f' % r2 +' Vietoris-Rips Complex')

plt.subplot(3,3,9)
plt.scatter(data[:,0],data[:,1],color='black',s=50)
plt.xlim(-1,2)
plt.ylim(-1,2)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
x=np.asarray([0,1])
y1=np.asarray([0,0])
y2=np.asarray([1,1])
plt.fill_between(x,y1,y2,facecolor='r')
plt.plot([0,1],[1,1],color='black',linewidth=4)
plt.plot([0,1],[0,0],color='black',linewidth=4)
plt.plot([0,0],[1,0],color='black',linewidth=4)
plt.plot([1,1],[1,0],color='black',linewidth=4)
plt.grid(False)
plt.title('F) Geometric Realization of\n Radius ' +  '%0.2f' % r3 +' Vietoris-Rips Complex')

plt.tight_layout()
plt.show()
'''


